﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class PopWin_proviewdialog : System.Web.UI.Page
{
    PM.PMSys.setmanager setmanager = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["pid"] != null && Request.QueryString["tid"] != null)
            {
                string id = Request.QueryString["pid"].ToString();
                string tid = Request.QueryString["tid"].ToString();
                this.HiddenField1.Value = id;
                this.HiddenField2.Value = tid;
                //绑定下拉框
                PM.Code.Web.controlbind.BindDropDownList(ddlCollege, "select collegename,collegeid from Dict_College", "collegename", "collegeid");
                this.ddlCollege.Items.Insert(0, new ListItem("——学院名——", "0"));
                this.ddlTname.Items.Insert(0, new ListItem("——姓名——", "0"));
                this.ddlTname.SelectedIndex = 0;
            }
        }
    }

    protected void ddlCollege_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.ddlTname.Items.Clear();
        string value = this.ddlCollege.SelectedItem.Text.Trim();
        string sqlstr = "select name,tid from Sys_Account where status=1 and usertype<>2 and usertype<>4 and depart='" + value + "'";
        if (value != string.Empty)
        {
            PM.Code.Web.controlbind.BindDropDownList(this.ddlTname, sqlstr, "name", "tid");
            this.ddlTname.Items.Remove(this.ddlTname.Items.FindByValue(this.HiddenField2.Value.Trim()));
            this.ddlTname.Items.Insert(0, new ListItem("——姓名——", "0"));
        }
        else
            return;
    }

    //执行数据库操作,同时触发更新Sys_Account和Dict_College两张表（不用存储过程）
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (this.ddlTname.SelectedIndex != 0)
        {
            setmanager = new PM.PMSys.setmanager();
            int result = setmanager.Appointment(Convert.ToInt32(this.HiddenField1.Value.Trim()), ddlTname.SelectedValue.Trim(), ddlTname.SelectedItem.Text.Trim(), "p");
            lbltips.Text = "设置成功！";
            btnSubmit.Enabled = false;
        }
        else
            lbltips.Text = "您未选择任何教师";
    }
}
